Repository navigation
auth: key the peer rate-limit bucket on the trusted proxy address - #3504
Conversation
The peer bucket used REMOTE_ADDR, which behind the edge is the proxy for every browser, so 20 failed logins anywhere locked the whole site out for 10 minutes. The bucket now keys on the address the edge accepted the connection from, and the gateway overwrites X-Forwarded-For instead of appending to it. A header is believed only from a loopback peer, so a direct caller cannot choose its bucket. Refs #3502
|
Local full suite on this head, for the log reference in the description. Tree: This is a local run on the exact head tree, not a CI conclusion. CI on |
|
Lead review — bound to head Change: 4 files +75/-5 — Rule checks: trailer is Acceptance evidence:
Not claimed: real nginx in front of the app was not run; the deployment is unverified. |
What this changes
The peer bucket in
App.rate_limitcountedREMOTE_ADDR. Behind the edge that address is the proxy, so every browser shared one bucket: 20 failed logins from anywhere locked the whole site out of/register,/loginand OIDC start for the 600 s window.flybot_workspace/app.py: newclient_address(env)returns the address the edge accepted the connection from when the peer is loopback andX-Forwarded-Forholds one valid address; otherwise it returnsREMOTE_ADDRunchanged. A malformed or oversized header from a loopback peer is refused with 400invalid, not counted. The peer bucket inrate_limitkeys on it, soregister,loginandoidc_startall use the client address.flybot_workspace/dsbot_gateway.py: the renderedlocation /block now setsproxy_set_header X-Forwarded-For $remote_addr;— overwrite, not append, so a value the caller put in front of it never reaches the platform.tests/test_management.py,tests/test_dsbot_gateway.py: three auth cases (distinct forwarded addresses get distinct buckets, a non-loopback peer cannot choose its bucket, a mixed header is refused) and one render assertion for the header.A header is believed only from a loopback peer, which is why the gateway must overwrite it: a direct caller elsewhere cannot pick its own bucket with a made-up value.
Not in this slice
The
/social/block's$proxy_add_x_forwarded_forand/v1/composio/callbackare unchanged;name:andoidc:buckets are unchanged; making the three limits configurable (the issue's option B) is not done.Verification
Local only, bound to head
1e4434ad920ef6e274ae0aea327c4987bb5a1004/ treedfd056dfb7c82a5248e500e1401b4b112a2bad82; no CI read for this head yet.python3 -m unittest discover -s testson that tree: see the check log below.--insecure-local --open-registration): 22 registrations with 22 distinctX-Forwarded-Forvalues -> 22x 201 (before the change the 21st was 429); 20 without the header -> 20x 201 then 429rate_limited; a mixed header ("198.51.100.1, 10.0.0.1") -> 400invalid.dsbot_gateway renderrc 0 and the renderedlocation /carries the new header line.Not run here: real nginx in front of the app. The rendered config and the loopback trust rule are verified, the deployment is not.
Risk is on the auth path and the gateway renderer; no keys, no new dependencies, no upstream pin change.
Refs #3502